package com.lemt.mall.controller;

import com.lemt.common.result.Res;
import com.lemt.mall.entity.ShoppingCart;
import com.lemt.mall.service.IShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zik
 * @since 2023-09-10
 */
@Slf4j
@Api(tags = "购物车")
@RestController
@RequestMapping("/mall/shoppingCart")
public class ShoppingCartController {

    @Resource(name = "ShoppingCartService")
    private IShoppingCartService shoppingCartService;


    @ApiOperation("添加到购物车")
    @PostMapping("/addShoppingCart")
    private Res<Boolean> addShoppingCart(@RequestBody ShoppingCart shoppingCart){
        log.info("{}",shoppingCart);
        return Res.ok(shoppingCartService.saveShoppingCart(shoppingCart));
    }

    @ApiOperation("根据id删除购物车")
    @DeleteMapping("/removeCart/{id}")
    private Res<Boolean> removeCart(@PathVariable Integer id){
        return Res.ok(shoppingCartService.removeById(id));
    }

    @ApiOperation("购物车分页")
    @GetMapping("/getCartPage")
    private Res getCartPage(@RequestParam Integer page , @RequestParam Integer pageSize ,@RequestParam(defaultValue = "") String name,@RequestParam Integer userId){
        return Res.ok(shoppingCartService.getCartPage(page,page,name,userId));
    }


}
